package com.aiwiown.snackmq.console.web;

import com.aiwiown.snackmq.common.dto.console.ExchangeInfoDTO;
import com.aiwiown.snackmq.console.service.SnackMQAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api")
public class ExchangeApiController {

    @Autowired
    private SnackMQAdminService adminService;

    @GetMapping("/exchanges")
    public ResponseEntity<?> listExchanges() {
        try {
            List<ExchangeInfoDTO> exchanges = adminService.listExchanges();
            return ResponseEntity.ok(exchanges);
        } catch (Exception e) {
            log.warn("Failed to fetch exchange list for API: {}", e.getMessage());
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to fetch exchanges: " + e.getMessage());
        }
    }
}